********************************************************************************
** 	TITLE: f14_cfs_effects_work_inmate.do

**	PROJECT: IGNITE
** 
**  PURPOSE: Appendix Table XIV: Effects of High IGNITE Exposure: Custody Staff Views on
**		Correctional Rehabilitation and Education Programming
********************************************************************************
		set sortseed 13

use "$output_data/IGNITE_corrections_survey_clean.dta", clear

gen d_female = 1-d_male

gen treatment = d_contact
gen post = !d_work_preignite
la var post "Started Work after IGNITE"
la var d_postcovid "Started Work after Covid"
la var d_female "Female"

local covs  d_female d_black  d_age_1 d_age_2 d_age_3 d_age_4 post d_postcovid

gen mi_any = 0
foreach var in `covs'{
	replace `var' = -99 if `var' == .
	replace mi_any = 1 if `var' == -99 
}

keep if !mi_any

/***********************************************
regressions
***********************************************/
local d_work_inmate d_work_inmates_1 d_work_inmates_2 d_work_inmates_3 

la var d_work_inmates_1 "Rehab. Programs Worth Time \& Money"
la var d_work_inmates_2 "Educ. Programs Worth Time \& Money"
la var d_work_inmates_3 "Rehab. as Important as Punishment"

* F test
reg treatment `covs'  i.survey_month
local N = e(N)
di `N'

		cap file close fh
		cap erase "$tables/correctional_survey_effects_d_work_inmate.tex"
		file open fh using "$tables/correctional_survey_effects_d_work_inmate.tex", write replace
		
		foreach v in `d_work_inmate' {
			reg `v' d_contact i.survey_month, r
			local b_`v' : di %8.3f _b[d_contact]
			local b_`v' = subinstr("`b_`v''"," ","",.)
			
			
			lincom d_contact
			local se_`v': di %8.3f r(se)
			local se_`v' = subinstr("(`se_`v'')"," ","",.)
			
			local p = r(p)
			local sig_`v' " "
			if `p'<0.1{
				local sig_`v' "$ ^{*} $ "
			}
			if `p'<0.05{
				local sig_`v' "$ ^{**} $ "
			}
			if `p'<0.01{
				local sig_`v' "$ ^{***} $ "
			}
			
			local lab_`v': var label `v'
			local b_`v' =  "`b_`v''`sig_`v''"
			su `v' if e(sample)&!d_contact, de
			local raw_mean = r(mean)
			local raw_mean: di %8.3f `raw_mean'
			local m_`v' = subinstr("`raw_mean'"," ","",.)
			
			file write fh ///
				"`lab_`v'' & `b_`v''& `se_`v''& `m_`v'' &	`N' \\ "_n
		}
		
		reg d_contact `d_work_inmate'  i.survey_month, r
		testparm `d_work_inmate'
		
		local f_stat : di %8.3f r(F)
		local f_stat_d_work_inmate = subinstr("`f_stat'"," ","",.)

		local f_p : di %8.3f r(p)
		local sig_`v' " "
		if `f_p'<0.1{
		local sig_`v' "$ ^{*} $ "
		}
		if `f_p'<0.05{
			local sig_`v' "$ ^{**} $ "
		}
		if `f_p'<0.01{
			local sig_`v' "$ ^{***} $ "
		}
		local f_p_d_work_inmate = subinstr("`f_p'"," ","",.)
		
		file write fh ///
			"\vspace{-.4cm} \\ " _n /// 
			"\cline{2-5} \vspace{-.4cm} \\ " _n /// 
			" \emph{F}-Test for Joint Test [\emph{p}-Value] & `f_stat_d_work_inmate'`sig_`v'' & [`f_p_d_work_inmate']&   &	`N' \\ "_n
			
		cap file close fh
		macro drop fh